﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Configuration;
using Topshelf;
using Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Hosting;
namespace iTelluro.Explorer.Program
{
    using Setting;
    public class WarningServices : ServiceControl
    {
        IDisposable handler = null;

        public WarningServices()
        {

        }
        public bool Start(HostControl hostControl)
        {
            var options = new StartOptions();
            foreach (var url in AppSetting.ListenIps)
            {
                options.Urls.Add(url);
            }

            handler = WebApp.Start<Startup>(options);
            Console.WriteLine("Server running at :");
            foreach (var url in options.Urls)
            {
                Console.WriteLine(string.Format("\t\t{0}", url));
            }

            Console.ReadLine();
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            handler.Dispose();
            return true;
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            appBuilder.UseCors(CorsOptions.AllowAll);
            HttpConfiguration config = new HttpConfiguration();
           //预警信息显示
            config.Routes.MapHttpRoute(
              "warningdata",
              "api/{controller}");
            //卫星图片时间获取
            config.Routes.MapHttpRoute(
               "clound",
               "api/{controller}/{time}");
            //卫星图片二进制流获取
            config.Routes.MapHttpRoute(
                "clound1",
                "api/{controller}/{time}/{type}/{StarType}");
            //雷达图片获取
            config.Routes.MapHttpRoute(
               "Radar",
               "api/{controller}/{time}/{station}");
           // 下载保存成Excel表格
           config.Routes.MapHttpRoute(
              "download",
              "api/{controller}/{location}/{name}/{name1}/{name2}/{name3}/{name4}");
            ////重要报显示
            config.Routes.MapHttpRoute(
                "storage1",
                "api/{controller}/{name}/{name1}/{name2}/{name3}/{name4}");
          //  config.Routes.MapHttpRoute(
          //    "storage2",
           //   "api/{controller}/{swtime}/{name1}/{name2}/{name3}/{name4}/{name}");
            //渲染图片获取
            config.Routes.MapHttpRoute(
                 "RenderResponse",
                 "api/{controller}/{time}/{type}/{area}/{time1}");
            //渲染图片
            config.Routes.MapHttpRoute(
                  "RenderCache",
                 "api/{controller}/{time}/{type}/{area}/{bigType}/{time1}/{mapname}/{isHourOrDay}");
            //预警信息分页
            config.Routes.MapHttpRoute(
             "DataQuery2",
             "api/{controller}/{pageIndex}/{pageSize}/{name}/{name2}/{name3}/{name4}/{name5}/{name6}");
            config.Routes.MapHttpRoute(
              "DataQuery3",
              "api/{controller}/{pageIndex}/{pageSize}/{name}/{count}/{name2}/{name3}/{name4}/{name5}/{name6}");
            //重要报分页
            config.Routes.MapHttpRoute(
                "zhongyaobaoP1",
                "api/{controller}/{pageIndex}/{pageSize}/{name}/{name1}/{name2}/{name3}/{name4}/{name5}/{name6}/{name7}");
            config.Routes.MapHttpRoute(
                "zhongyaobaop2",
                "api/{controller}/{pageIndex}/{pageSize}/{name}/{count}/{name1}/{name2}/{name3}/{name4}/{name5}/{name6}/{name7}");
            config.Routes.MapHttpRoute(
              "zhongyaobaop3",
              "api/{controller}/{ID}/{name}/{name2}/{name3}/{name4}/{name5}/{name6}/{name7}/{name8}/{name9}/{name10}/{name11}");
            config.Routes.MapHttpRoute(
               "feedback",
               "api/{controller}/{name}/{name1}/{name2}/{name3}/{name4}/{name5}/{name6}/{name7}/{name8}/{tele}/{dpart}/{email}/{qq}/{message}"
               );
            appBuilder.UseWebApi(config);
           
        }

    }
}
